package com.easylinkin.linkappapi.jzsmokewarning.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.easylinkin.linkappapi.common.model.RequestModel;
import com.easylinkin.linkappapi.jzsmokewarning.entity.SmokeWarning;
import com.easylinkin.linkappapi.jzsmokewarning.service.SmokeWarningService;
import com.easylinkin.linkappapi.jzsmokewarning.service.impl.TimingWarningImpl;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * <p>
 * 荆州油烟预警 前端控制器
 * </p>
 *
 * @author TongJie
 * @since 2021-12-20
 */
@RestController
@RequestMapping("/jzsmokewarning/smokeWarning")
public class SmokeWarningController {


    @Resource
    private SmokeWarningService service;

    @Resource
    private TimingWarningImpl timingWarningService;

    @ApiOperation("油烟采集数据分页数据")
    @PostMapping("getSmokeCollectionPage")
    public RestMessage getSmokeCollectionPage(@RequestBody RequestModel<SmokeWarning> requestModel) {
        Assert.notNull(requestModel.getCustomQueryParams(), "customQueryParams 不能为空");
        Assert.notNull(requestModel.getPage(), "page 不能为空");
        IPage<SmokeWarning> record = service.getSmokeCollectionPage(requestModel.getPage(), requestModel.getSorts(), requestModel.getCustomQueryParams());
        return RestBuilders.successBuilder().data(record).build();
    }
    @ApiOperation("油烟采集数据导出")
    @PostMapping("exportData")
    public void exportData(@RequestBody SmokeWarning smokeWarning, HttpServletRequest request, HttpServletResponse response) {
        service.exportData(smokeWarning, request, response);
    }

    @ApiOperation("定时采集统计测试")
    @PostMapping("test")
    public RestMessage test() {
        timingWarningService.test();
        return RestBuilders.successBuilder().data(null).build();
    }

}
